package com.job.controller;

import com.job.common.ResponseResult;
import com.job.common.enums.ResultCodeEnum;
import com.job.common.exception.LoginException;
import com.job.common.exception.RegisterException;
import com.job.common.exception.UserUpdateException;
import com.job.controller.req.LoginVo;
import com.job.controller.req.RegisterReqVO;
import com.job.controller.req.hrCorporationBandReqVO;
import com.job.service.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Map;

@RestController
@RequestMapping("/user")
@Api("用户接口")
public class LoginController {

    @Resource
    private LoginService loginService;

    @PostMapping("/login")
    @ApiOperation("登录接口")
    public ResponseResult<Map<String,String>> login(@RequestBody LoginVo loginVo) throws LoginException {
        return loginService.login(loginVo);
    }

    @GetMapping("/logout")
    @ApiOperation("退出登录接口")
    public ResponseResult<ResultCodeEnum> logout(){
        return loginService.logout();
    }


    @PostMapping("/register")
    @ApiOperation("注册接口")
    public ResponseResult<Long> register(@Valid @RequestBody RegisterReqVO registerReqVO) throws RegisterException {
        return loginService.register(registerReqVO);
    }

    @PostMapping("/hrInfoBand")
    @ApiOperation("如果是hr,要填写的额外信息")
    public ResponseResult<ResultCodeEnum> hrCorporationBand(@Valid @RequestBody hrCorporationBandReqVO hrCorporationBandReqVO)
            throws UserUpdateException {
        return loginService.hrCorporationBand(hrCorporationBandReqVO);
    }

    @PostMapping
    @ApiOperation("头像上传")
    public ResponseResult<String> uploadTitle(MultipartFile file,Integer userId) throws Exception{
        return   loginService.uploadTitle(file,userId);
    }
}
